package dragon.tagext.easyui;

import java.util.Map;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyTagSupport;

import dragon.core.system.po.SysUser;
import dragon.core.util.GlobalParameter;
import dragon.core.util.StringUtils;
import dragon.model.bizObject.BizField;
import dragon.model.bizObject.BizObject;
import dragon.model.bizObject.BizProcess;
import dragon.model.bizObject.QueryField;
import dragon.model.fieldTemplate.FieldTemplateDao;
import dragon.model.permission.PermissionCheck;
import dragon.modules.system.config.dao.SysConfig;

@SuppressWarnings("serial")
public class ModMaster extends BodyTagSupport {

	private String js;
	private String html;

	@Override
	public int doStartTag() throws JspException {
		BizObject bizObject = (BizObject) pageContext.getRequest().getAttribute("bizObject");
		SysUser user = (SysUser) pageContext.getSession().getAttribute(GlobalParameter.User);
		boolean hasOpenUrl = false;
		try {
			if (bizObject != null) {

				StringBuffer queryString = new StringBuffer();
				if (bizObject.getQueryFields() != null) {
					for (QueryField qf : bizObject.getQueryFields()) {
						queryString.append("&").append(qf.getCode().toUpperCase()).append("=").append(pageContext.getRequest().getParameter(qf.getCode().toUpperCase()));
					}
					if (queryString.length() > 0)
						queryString.deleteCharAt(0);
				}

				StringBuffer sb_js = new StringBuffer();
				StringBuffer sb_html = new StringBuffer();

				sb_js.append("var kindeditors = new Map();\n");
				sb_js.append("var fieldsType = new Map();\n");
				sb_js.append("$(function() {\n");
				// 添加用户初始化fun
				sb_js.append("\tif($.isFunction(window.init_before))").append("{\n\t\tinit_before();\n\t}\n");
				// from表单开始
				sb_js.append("\t$('#myform').form({\n");
				sb_js.append("\t\turl : 'dragon/model/action/BizObjectHandler/mod.ejw',\n");
				sb_js.append("\t\tonSubmit : function() {\n");
				sb_js.append("\t\t\ttop.showProgress();\n");
				sb_js.append("\t\t\tvar isValid = $(this).form('validate');\n");
				sb_js.append("if(window.before_submit){if(!before_submit()){isValid = false;}}");
				sb_js.append("\t\t\tif(!isValid){top.hideProgress();}\n");
				sb_js.append("\t\t\treturn isValid;\n");
				sb_js.append("\t\t},\n");
				sb_js.append("\t\tsuccess : function(data) {\n");
				sb_js.append("\t\t\ttop.hideProgress();");
				sb_js.append("\t\t\ttry{\n\t\t\t\tdata = eval('(' + data + ')');\n\t\t\t}catch(e){\n\t\t\t\ttop.showErrorMsg(\"出错了\", data);\n\t\t\t\treturn;\n\t\t\t}\n");
				sb_js.append("\t\t\tif(data.MESSAGE_ERROR != undefined && data.MESSAGE_ERROR != ''){\n\t\t\t\ttop.showMsg(\"错误\", data.MESSAGE_ERROR, true,'error');\n");
				sb_js.append("\t\t\t}else if(data.MESSAGE_WARNING != undefined && data.MESSAGE_WARNING != ''){\n\t\t\t\ttop.showMsg(\"警告\", data.MESSAGE_WARNING, true,'warning');\n");
				sb_js.append("\t\t\t}else{\n\t\t\t\tif(data.MESSAGE_INFO != undefined && data.MESSAGE_INFO != ''){\n\t\t\t\t\ttop.showMsg(\"\", data.MESSAGE_INFO, false);\n\t\t\t\t}else{\n\t\t\t\t\ttop.showMsg(\"\",\"修改成功！\", false); \n\t\t\t\t}\n");

				sb_js.append("\t\t\ttop.$('#tabsconetnt').tabs('getSelected').find('iframe')[0].contentWindow.$('#mydatagrid').datagrid('reload');\n");
				sb_js.append("afterSave(data.parameters);");
				sb_js.append("\t\t\t}\n");
				sb_js.append("\t\t}\n");
				sb_js.append("\t});\n");

				// 主表字段类型
				if (!bizObject.getBizFields().isEmpty()) {
					for (BizField bf : bizObject.getBizFields()) {
						if (bf.getFieldTemplate() != null) {
							switch (bf.getFieldTemplate().getType()) {
							case DATETIME:
								sb_js.append("\tfieldsType.put('").append(bf.getCode().toUpperCase()).append("','datebox');\n");
								break;
							case DATE:
								sb_js.append("\tfieldsType.put('").append(bf.getCode().toUpperCase()).append("','datebox');\n");
								break;
							case TIME:
								sb_js.append("\tfieldsType.put('").append(bf.getCode().toUpperCase()).append("','timespinner');\n");
								break;
							case SELECT:
								sb_js.append("\tfieldsType.put('").append(bf.getCode().toUpperCase()).append("','combotree").append(bf.getFieldTemplate().getMultiple() == 0 ? "" : "-multiple")
										.append("');\n");
								break;
							case RADIO:
								if (bf.getFieldTemplate().getProto() == 1) {
									sb_js.append("\tfieldsType.put('").append(bf.getCode().toUpperCase()).append("','radio');\n");
								} else if (bf.getFieldTemplate().getProto() == 0) {
									sb_js.append("\tfieldsType.put('").append(bf.getCode().toUpperCase()).append("','combobox").append(bf.getFieldTemplate().getMultiple() == 0 ? "" : "-multiple")
											.append("');\n");
								}
								break;
							case CHECKBOX:
								if (bf.getFieldTemplate().getProto() == 1) {
									sb_js.append("\tfieldsType.put('").append(bf.getCode().toUpperCase()).append("','checkbox');\n");
								} else if (bf.getFieldTemplate().getProto() == 0) {
									sb_js.append("\tfieldsType.put('").append(bf.getCode().toUpperCase()).append("','combobox").append(bf.getFieldTemplate().getMultiple() == 0 ? "" : "-multiple")
											.append("');\n");
								}
								break;
							default:
								sb_js.append("\tfieldsType.put('").append(bf.getCode().toUpperCase()).append("','text');\n");
								break;
							}
						} else {
							sb_js.append("\tfieldsType.put('").append(bf.getCode().toUpperCase()).append("','text');\n");
						}
					}
				}
				// 主表字段模板
				if (!bizObject.getBizFields().isEmpty()) {
					sb_js.append("\tvar value = '';\n");
					for (BizField bf : bizObject.getBizFields()) {
						if (bf.getFieldTemplate() != null) {
							switch (bf.getFieldTemplate().getType()) {
							case DATETIME:
								sb_js.append("\t$('#").append(bf.getCode()).append("').datebox({");
								sb_js.append("formatter : function(date) {");
								sb_js.append("return date.Format(\"").append(bf.getFieldTemplate().getFormat()).append("\");");
								sb_js.append("}");
								sb_js.append("});\n");
								break;
							case DATE:
								sb_js.append("\t$('#").append(bf.getCode()).append("').datebox({");
								sb_js.append("formatter : function(date) {");
								sb_js.append("return date.Format(\"").append(bf.getFieldTemplate().getFormat()).append("\");");
								sb_js.append("}");
								sb_js.append("});\n");
								break;
							case SELECT:
								sb_js.append("\t$('#").append(bf.getCode().toUpperCase()).append("').combotree({");
								sb_js.append("onBeforeSelect : function(node) {");
								sb_js.append("if(node.state!=undefined&&").append(bf.getFieldTemplate().getOnlyLeafSelect() == 1 ? "true" : "false").append("){return false;}},");
								sb_js.append("onLoadSuccess : function(node, data) {");
								sb_js.append("var tree = $('#").append(bf.getCode().toUpperCase()).append("').combotree('tree');");
								sb_js.append("var roots = tree.tree('getRoots');");
								sb_js.append("for ( var i = roots.length - 1; i >= 0; i--) {tree.tree('expandAll', roots[i].target);}roots = null;	tree = null;");
								sb_js.append("}});\n");
								break;
							case RICHTEXT:
								sb_js.append("\tvar ").append(bf.getCode()).append("id;");
								sb_js.append("$.getScript('plugins/").append(SysConfig.getParameter(GlobalParameter.KindeditorRelease)).append("/kindeditor-min.js', function() {");
								sb_js.append("KindEditor.basePath = 'plugins/").append(SysConfig.getParameter(GlobalParameter.KindeditorRelease)).append("/';");
								sb_js.append(bf.getCode()).append(" = ").append("KindEditor.create('textarea[name=\"").append(bf.getCode().toUpperCase()).append("\"]');");
								sb_js.append("kindeditors.put('").append(bf.getCode()).append("',").append(bf.getCode()).append(");");
								sb_js.append("});\n");
								break;
							case CHECKBOX:
								if (bf.getFieldTemplate().getProto() == 0) {
									sb_js.append("\tvalue = '").append(bf.getValue() == null ? "" : bf.getValue()).append("';");
									sb_js.append("if(value!=''){");
									sb_js.append("$('#").append(bf.getCode().toUpperCase()).append("').combobox('setValues',value.split(\",\"));");
									sb_js.append("}\n");
								}
								break;
							default:
								break;
							}
						}
					}
					// 从表js
					for (int i = 0; i < bizObject.getDependby().size(); i++) {
						BizObject bo = bizObject.getDependby().get(i);
						StringBuffer dependParam = new StringBuffer();

						if (bo.getDepend() != null) {
							dependParam.append("&").append(bo.getDependParamK().toUpperCase()).append("=").append(pageContext.getRequest().getParameter(bo.getDependParamV().toUpperCase()));
						}
						if (bo.getQueryFields() != null) {
							for (QueryField qf : bo.getQueryFields()) {
								if (!dependParam.toString().contains(qf.getCode().toUpperCase())) {
									String tempParamValue = pageContext.getRequest().getParameter(qf.getCode().toUpperCase());
									if (!StringUtils.isEmpty(tempParamValue)) {
										dependParam.append("&").append(qf.getCode().toUpperCase()).append("=").append(tempParamValue);
									}
								}
							}
						}

						//
						// 配置datagrid属性
						sb_js.append("\t$('#mydatagrid_").append(bo.getCode()).append("').datagrid({\n\t\turl : 'dragon/model/action/BizObjectHandler/loadData.ejw?bizCode=").append(bo.getCode());
						if (dependParam.length() > 0) {
							sb_js.append(dependParam);
						}
						sb_js.append("',\n");
						sb_js.append("\t\tsingleSelect :").append(bo.getSingleSelect() == 0 ? "false" : "true").append(",\n");
						sb_js.append("\t\tpagination :").append(bo.getPagination() == 0 ? "false" : "true").append(",\n");
						sb_js.append("\t\tpageSize :").append(bo.getPageSize()).append(",\n");
						sb_js.append("\t\tpageList : [").append(bo.getPageList()).append("],\n");
						sb_js.append("\t\tremoteSort :").append(bo.getRemoteSort() == 0 ? "false" : "true").append(",\n");
						sb_js.append("\t\trownumbers :").append(bo.getRownumbers() == 0 ? "false" : "true").append(",\n");
						// 配置结束

						// 绘制锁定列开始
						java.util.List<BizField> frozen = bo.getBizFieldsBind().get("FROZEN");
						if (frozen != null && !frozen.isEmpty()) {
							sb_js.append("\t\tfrozenColumns:[[\n");
							if (bo.getSingleSelect() == 0)
								sb_js.append("\t\t\t{checkbox : true},\n");
							for (BizField bf : frozen) {
								sb_js.append("\t\t\t{");
								sb_js.append("field: '").append(bf.getCode().toUpperCase()).append("',");
								sb_js.append("title: '").append(bf.getName()).append("',");
								sb_js.append("width: ").append(bf.getWidth()).append(",");
								sb_js.append("sortable :").append(bf.getSortable() == 0 ? "false" : "true");
								sb_js.append("},\n");
							}
							sb_js.deleteCharAt(sb_js.lastIndexOf(","));
							sb_js.append("\t\t]],\n");
						}
						// 绘制锁定列结束

						// 绘制普通列开始
						sb_js.append("\t\tcolumns : [[\n");
						if ((frozen == null || frozen.isEmpty()) && bo.getSingleSelect() == 0)
							sb_js.append("\t\t\t{checkbox : true},\n");
						java.util.List<BizField> nofrozen = bo.getBizFieldsBind().get("NONFROZEN");
						for (BizField bf : nofrozen) {
							String width = bf.getWidth();
							sb_js.append("\t\t\t{");
							sb_js.append("field: '").append(bf.getCode().toUpperCase()).append("',");
							sb_js.append("title: '").append(bf.getName()).append("',");

							sb_js.append("sortable :").append(bf.getSortable() == 0 ? "false" : "true").append(",");
							sb_js.append("hidden :").append(bf.getIsVisible() == 1 ? "false" : "true");
							if (bf.getFormatter() != null) {
								sb_js.append(",formatter:function(value,rowData,rowIndex){").append(bf.getFormatter()).append("}");
							}
							if (bf.getFormatter() == null && bf.getFieldTemplate() != null) {
								switch (bf.getFieldTemplate().getType()) {
								case DATE:
									width = "80";
									sb_js.append(",formatter:function(value,rowData,rowIndex){return fmtDateStr(value);}");
									break;
								case TIME:
									width = "60";
									sb_js.append(",formatter:function(value,rowData,rowIndex){return fmtTimeStr(value);}");
									break;
								case DATETIME:
									width = "120";
									sb_js.append(",formatter:function(value,rowData,rowIndex){return fmtDateTimeStr(value);}");
									break;
								case FILE:
									sb_js.append(",formatter:function(value,rowData,rowIndex){return getFiles(value);}");
									break;
								case RADIO:
									sb_js.append(",formatter:function(value,rowData,rowIndex){return getValuesText('")
											.append(bf.getFieldTemplate().getOptions() == null ? "" : bf.getFieldTemplate().getOptions()).append("',value);}");
									break;
								case CHECKBOX:
									sb_js.append(",formatter:function(value,rowData,rowIndex){return getValuesText('")
											.append(bf.getFieldTemplate().getOptions() == null ? "" : bf.getFieldTemplate().getOptions()).append("',value);}");
									break;
								default:
									if (!StringUtils.isEmpty(bf.getFieldTemplate().getOptions())) {
										sb_js.append(",formatter:function(value,rowData,rowIndex){return getValuesText('")
												.append(bf.getFieldTemplate().getOptions() == null ? "" : bf.getFieldTemplate().getOptions()).append("',value);}");
									}
									break;
								}
							}
							sb_js.append(",width: ").append(width);
							sb_js.append("},\n");
						}
						sb_js.deleteCharAt(sb_js.lastIndexOf(","));
						sb_js.append("\t\t]],\n");
						// 绘制普通列结束

						// 添加toolbar
						boolean iscut = false;
						sb_js.append("\t\ttoolbar : [\n");
						if (bo.getInsert() == 1 && PermissionCheck.checkProcessPermission(user, bizObject.getCode(), "add")) {
							iscut = true;
							sb_js.append("\t\t\t{text : '添加',iconCls : 'icon-add',handler : function() {\n");

							// 判断用户是否自定义方法，并添加默认方法
							sb_js.append("\t\t\t\tif($.isFunction(window.add))").append("{\n\t\t\t\t\tadd();\n\t\t\t\t}");
							sb_js.append("else{\n");

							sb_js.append("\t\t\t\t\ttop.showWindow(\"AddSlave\", \"新增").append(bo.getName()).append("\", \"dragon/model/action/BizObjectHandler/preAdd.ejw?bizCode=")
									.append(bo.getCode()).append(dependParam.length() > 0 ? dependParam : "").append("\", ").append(bo.getAddWindowWidth()).append(", ")
									.append(bo.getAddWindowHeight()).append(", ").append(bo.getMaximizable()).append(", ").append(bo.getMaximize()).append(");\n");
							sb_js.append("\t\t\t\t}\n");
							sb_js.append("\t\t\t}}");
						}
						if (bo.getUpdate() == 1 && PermissionCheck.checkProcessPermission(user, bizObject.getCode(), "mod")) {
							if (iscut) {
								sb_js.append(",'-',\n");
							} else {
								iscut = true;
							}
							sb_js.append("\t\t\t{text : '修改',iconCls : 'icon-edit',handler : function() {\n");
							// 判断用户是否自定义方法，并添加默认方法
							sb_js.append("\t\t\t\tif($.isFunction(window.mod))").append("{\n\t\t\t\t\tmod();\n\t\t\t\t}");
							sb_js.append("else{\n");
							sb_js.append("\t\t\t\t\tvar rows = $('#mydatagrid_").append(bo.getCode()).append("').datagrid('getSelections');\n");
							sb_js.append("\t\t\t\t\tif(rows.length!=1){\n\t\t\t\t\t\t top.showMsg(\"\", \"请选择一行数据！\", true, \"warning\");\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n");
							sb_js.append("\t\t\t\t\tvar params = parseParam(rows[0]);\n");
							sb_js.append("\t\t\t\ttop.showWindow(\"ModSlave\", \"修改 ").append(bo.getName()).append("\", \"dragon/model/action/BizObjectHandler/preMod.ejw?bizCode=")
									.append(bo.getCode()).append(dependParam).append("&\"+params, ").append(bo.getAddWindowWidth()).append(", ").append(bo.getAddWindowHeight()).append(", ")
									.append(bo.getMaximizable()).append(", ").append(bo.getMaximize()).append(");\n");
							sb_js.append("\t\t\t\t}\n");
							sb_js.append("\t\t\t}}");

						}
						if (bo.getDelete() == 1 && PermissionCheck.checkProcessPermission(user, bizObject.getCode(), "del")) {
							if (iscut) {
								sb_js.append(",'-',\n");
							} else {
								iscut = true;
							}
							sb_js.append("\t\t\t{text : '删除',iconCls : 'icon-cancel',handler : function() {\n");
							sb_js.append("\t\t\t\tif($.isFunction(window.del))").append("{\n\t\t\t\t\tdel();\n\t\t\t\t}");
							sb_js.append("else{\n");
							sb_js.append("\t\t\t\t\tvar rows = $('#mydatagrid_").append(bo.getCode()).append("').datagrid('getSelections');\n");
							sb_js.append("\t\t\t\t\tif(rows.length==0){\n\t\t\t\t\t\t top.showMsg(\"\", \"请选择需要删除的数据！\", true, \"warning\");\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n");
							sb_js.append("\t\t\t\t\ttop.showConfirm(\"删除确认\", \"是否删除所选的数据？\", function(){\n");
							sb_js.append("\t\t\t\t\t\t$.post(\"dragon/model/action/BizObjectHandler/del.ejw\", {bizCode:'").append(bo.getCode())
									.append("',rows : JSON.stringify(rows)}, function(data) {\n");
							sb_js.append("\t\t\t\t\t\t\ttry{\n\t\t\t\t\t\t\t\tdata = eval('(' + data + ')'); \n\t\t\t\t\t\t\t}catch(e){\n\t\t\t\t\t\t\t\ttop.showErrorMsg(\"出错了\", data);\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n");
							sb_js.append("\t\t\t\t\t\t\tif(data.MESSAGE_ERROR  != undefined && data.MESSAGE_ERROR != ''){\n\t\t\t\t\t\t\t\ttop.showMsg(\"错误\", data.MESSAGE_ERROR, true,'error');\n\t\t\t\t\t\t\t}else if(data.MESSAGE_WARNING != undefined && data.MESSAGE_WARNING != ''){\n\t\t\t\t\t\t\t\ttop.showMsg(\"警告\", data.MESSAGE_WARNING, true,'warning');\n");
							sb_js.append("\t\t\t\t\t\t\t}else{\n");
							sb_js.append("\t\t\t\t\t\t\t\tif(data.MESSAGE_INFO != undefined && data.MESSAGE_INFO != ''){\n\t\t\t\t\t\t\t\t\ttop.showMsg(\"\", data.MESSAGE_INFO, false);\n\t\t\t\t\t\t\t\t}else{\n\t\t\t\t\t\t\t\t\ttop.showMsg(\"\", \"删除成功！\", false);\n\t\t\t\t\t\t\t\t}\n");
							sb_js.append("\t\t\t\t\t\t\t\tfor (  var i = rows.length-1; i >=0; i--) {\n");
							sb_js.append("\t\t\t\t\t\t\t\t\tvar index = $('#mydatagrid_").append(bo.getCode()).append("').datagrid('getRowIndex', rows[i]);\n");
							sb_js.append("\t\t\t\t\t\t\t\t\t$('#mydatagrid_").append(bo.getCode()).append("').datagrid('deleteRow', index);\n");
							sb_js.append("\t\t\t\t\t\t\t\t}\n");
							sb_js.append("\t\t\t\t\t\t\t\trows = null;\n");
							sb_js.append("\t\t\t\t\t\t\t}\n\t\t\t\t\t\t }\n\t\t\t\t\t\t);\n\t\t\t\t\t}, null);\n");
							sb_js.append("\t\t\t\t}\n");
							sb_js.append("\t\t\t  }\n\t\t\t}\n");
						}
						if (bo.getView() == 1 && PermissionCheck.checkProcessPermission(user, bo.getCode(), "view")) {
							if (iscut) {
								sb_js.append(",'-',\n");
							} else {
								iscut = true;
							}
							sb_js.append("\t\t\t{text : '查看',iconCls : 'ext-icon-view',handler : function() {\n");
							sb_js.append("\t\t\t\tif($.isFunction(window.view))").append("{\n\t\t\t\t\tview();\n\t\t\t\t}");
							sb_js.append("else{\n");
							sb_js.append("\t\t\t\t\tvar rows = $('#mydatagrid').datagrid('getSelections');\n");
							sb_js.append("\t\t\t\t\tif(rows.length!=1){\n\t\t\t\t\t\t top.showMsg(\"\", \"请选择一行数据！\", true, \"warning\");\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n");
							sb_js.append("\t\t\t\t\tvar params = parseParam(rows[0]);\n");
							sb_js.append("top.showWindow('").append(bo.getDependon() == null ? "DefaultView" : "ViewSlave").append("',\"查看").append(bo.getName())
									.append("\",\"dragon/model/action/boHandler/view.ejw?bizCode=");
							sb_js.append(bo.getCode()).append("&\"+params,").append(bo.getViewWindowWidth()).append(",").append(bo.getViewWindowHeight()).append(",").append(bo.getMaximizable())
									.append(",").append(bo.getMaximizable()).append(");");
							sb_js.append("\t\t\t\t}\n");
							sb_js.append("\t\t\t}}");
						}

						if (bo.getProcesses() != null) {
							for (BizProcess bp : bo.getProcesses()) {
								if (bp.getFunctionCall() != null && "addmoddel".contains(bp.getFunctionCall()))
									continue;
								if (!PermissionCheck.checkProcessPermission(user, bo.getCode(), bp.getCode()) || !bp.getTarget().equalsIgnoreCase("list"))
									continue;
								if (iscut) {
									sb_js.append(",'-',\n");
								} else {
									iscut = true;
								}
								sb_js.append("\t\t\t{text :'").append(bp.getName()).append("', iconCls:'").append(bp.getIconCls()).append("',handler:function(){");
								if (!StringUtils.isEmpty(bp.getUrl())) {
									hasOpenUrl = true;
									sb_js.append(" openUrl('").append(bp.getUrl()).append("',").append(bp.getMultiple() == 1 ? true : false).append(",").append(bp.getPopWindow() == 1 ? true : false)
											.append(",'").append(bp.getName()).append("',").append(bp.getPopWindowWidth()).append(",").append(bp.getPopWindowHeight()).append(",")
											.append(bp.getMaximizable() == 1 ? true : false).append(",").append(bp.getMaximize() == 1 ? true : false).append(");");
								} else if (!StringUtils.isEmpty(bp.getFunctionCall())) {
									sb_js.append(bp.getFunctionCall()).append("();");
								} else {
									sb_js.append(bp.getScript());
								}
								sb_js.append("}}");

							}
						}
						sb_js.append("\n\t\t],\n");
						// 添加toolbar结束

						sb_js.append("\t\tonLoadError : function() {top.showErrorMsg(\"出错了\", \"加载数据遇到错误，请稍后重试！\");},\n");

						sb_js.append("\t\tonLoadSuccess : function(data) {if(data.errors!=undefined&&data.errors!=null){top.showErrorMsg(\"出错了\", \"加载数据遇到错误！\"+data.errors);}if(data.sessiontimeout!=undefined&&data.sessiontimeout==true){top.showMsg(\"出错了\", \"会话已过期，请按 &lt;F5&gt; 刷新页面并重新登录到系统！\",true);}},\n");

						sb_js.append("\t\tonClickRow : function(rowIndex, rowData) {if($.isFunction(window.clickRow)){clickRow(rowIndex, rowData);}else{}}\n");

						sb_js.append("\t});\n");// datagrid结束

						// 添加搜索项位置
						if (bo.getQueryFields() != null && !bo.getQueryFields().isEmpty())
							sb_js.append("$(\".datagrid-toolbar:eq(" + i + ")\").append($(\"#datagridsearch_" + bo.getCode() + "\"));").append(
									"$(\".datagrid-toolbar:eq(" + i + ")\").css(\"height\", \"auto\");");

						// 模板处理
						if (bo.getQueryFields() != null && !bo.getQueryFields().isEmpty()) {
							sb_js.append("\tvar value=\"\" ;");
							for (QueryField qf : bo.getQueryFields()) {
								if (qf.getFieldTemplate() != null && qf.getFieldTemplate().getType() != null) {
									switch (qf.getFieldTemplate().getType()) {
									case DATE:
										sb_js.append("\t$('#").append(qf.getCode().toUpperCase()).append("_").append(bo.getCode()).append("').datebox({");
										sb_js.append("formatter : function(date) {");
										sb_js.append("return date.Format(\"").append(qf.getFieldTemplate().getFormat()).append("\");");
										sb_js.append("}").append("});\n");
										break;
									case DATETIME:
										sb_js.append("\t$('#").append(qf.getCode().toUpperCase()).append("_").append(bo.getCode()).append("').datebox({");
										sb_js.append("formatter : function(date) {");
										sb_js.append("return date.Format(\"").append(qf.getFieldTemplate().getFormat()).append("\");");
										sb_js.append("}").append("});\n");
										break;
									case SELECT:
										sb_js.append("\t$('#").append(qf.getCode().toUpperCase()).append("_").append(bo.getCode()).append("').combotree({");
										sb_js.append("onBeforeSelect : function(node) {");
										sb_js.append("if(node.state!=undefined&&").append(qf.getFieldTemplate().getOnlyLeafSelect() == 1 ? "true" : "false").append("){return false;}},");
										sb_js.append("onLoadSuccess : function(node, data) {");
										sb_js.append("var tree = $('#").append(qf.getCode().toUpperCase()).append("').combotree('tree');");
										sb_js.append("var roots = tree.tree('getRoots');");
										sb_js.append("for ( var i = roots.length - 1; i >= 0; i--) {tree.tree('expandAll', roots[i].target);}roots = null;	tree = null;");
										sb_js.append("}});\n");
										break;
									default:
										break;
									}
								}
							}
						}

						//
					}
					// 从表js结束
					sb_js.append("\tif($.isFunction(window.init_after))").append("{\n\tinit_after();\n\t}\n");
					sb_js.append("});\n");

					// openurl方法
					if (hasOpenUrl) {
						sb_js.append("function openUrl(url,multiple,popWindow,title,popWindowWidth,popWindowHeight,maximizable,maximize){");
						sb_js.append("var rows = $('#mydatagrid').datagrid('getSelections');");
						sb_js.append("if(rows.length==0){top.showMsg(\"\", \"请选择需要操作的数据！\", true, \"warning\");return;");
						sb_js.append("}else{if(rows.length>1&&!multiple){top.showMsg(\"\", \"每次操作只能选择一条数据！\", true, \"warning\");return;}}");
						sb_js.append("if(popWindow){if(url.lastIndexOf('?')==url.length-1){	url += '?' + parseParam(rows[0]);}else{url += '&' + parseParam(rows[0]);}top.showWindow('popWindow', title, url, popWindowWidth, popWindowHeight, maximizable, maximize);");
						sb_js.append("}else{$.post(url,{ rows : JSON.stringify(rows)},function(data){");
						sb_js.append("if(data.result != undefined && data.result == true){ top.showMsg(\"\", \"操作成功！\", false); $('#mydatagrid').datagrid('reload'); }");
						sb_js.append("	if(data.MESSAGE_ERROR != undefined && data.MESSAGE_ERROR != ''){ top.showMsg(\"错误\", data.MESSAGE_ERROR, true,'error');");
						sb_js.append("}else if(data.MESSAGE_WARNING != undefined && data.MESSAGE_WARNING != ''){ top.showMsg(\"警告\", data.MESSAGE_WARNING, true,'warning');");
						sb_js.append("}else if(data.MESSAGE_INFO != undefined && data.MESSAGE_INFO != ''){ top.showMsg(\"\", data.MESSAGE_INFO, false); }},'json');");
						sb_js.append("}}");
					}

					// 从表搜索
					for (int i = 0; i < bizObject.getDependby().size(); i++) {
						BizObject bo = bizObject.getDependby().get(i);
						if (bo.getQueryFields() != null && !bo.getQueryFields().isEmpty()) {

							// 添加默认搜索方法
							sb_js.append("function query_").append(bo.getCode()).append("(){");
							sb_js.append("if($.isFunction(window.myquery_").append(bo.getCode()).append("))").append("{myquery_").append(bo.getCode()).append("();}");
							sb_js.append("else{");
							sb_js.append("var params = {");
							for (QueryField qf : bo.getQueryFields()) {

								if (qf.getFieldTemplate() == null) {
									sb_js.append(qf.getCode().toUpperCase()).append(": $('#").append(qf.getCode().toUpperCase()).append("_").append(bo.getCode()).append("').val()").append(",");
								} else if (qf.getFieldTemplate().getType().name().equals("TIME")) {
									sb_js.append(qf.getCode().toUpperCase()).append(": $('#").append(qf.getCode().toUpperCase()).append("').timespinner('getValue').trim()").append(",");
								} else if (qf.getFieldTemplate().getType().name().equals("DATETIME") || qf.getFieldTemplate().getType().name().equals("DATE")) {
									sb_js.append(qf.getCode().toUpperCase()).append(": $('#").append(qf.getCode().toUpperCase()).append("').")
											.append(qf.getFieldTemplate().getType().name().equals("DATE") ? "datebox" : "datetimebox").append("('getValue')").append(",");
								} else if (qf.getFieldTemplate().getType().name().equals("SELECT")) {
									sb_js.append(qf.getCode().toUpperCase()).append(": $('#").append(qf.getCode().toUpperCase()).append("_").append(bo.getCode()).append("').combotree('")
											.append(qf.getFieldTemplate().getMultiple() == 0 ? "getValue" : "getValues").append("')")
											.append(qf.getFieldTemplate().getMultiple() == 1 ? ".join(\",\")" : "").append(".trim(),");
								} else if (qf.getFieldTemplate().getType().name().equals("RADIO") || qf.getFieldTemplate().getType().name().equals("CHECKBOX")) {
									sb_js.append(qf.getCode().toUpperCase()).append(": $('#").append(qf.getCode().toUpperCase()).append("_").append(bo.getCode()).append("').combobox('")
											.append(qf.getFieldTemplate().getMultiple() == 0 ? "getValue" : "getValues").append("')")
											.append(qf.getFieldTemplate().getMultiple() == 1 ? ".join(\",\")" : "").append(".trim(),");
								}

							}
							sb_js.deleteCharAt(sb_js.lastIndexOf(","));
							sb_js.append("};");
							sb_js.append("$(\"#mydatagrid_").append(bo.getCode()).append("\").datagrid('options').url = 'dragon/model/action/BizObjectHandler/loadData.ejw?bizCode=")
									.append(bo.getCode()).append("';");
							sb_js.append("$(\"#mydatagrid_").append(bo.getCode()).append("\").datagrid('options').queryParams = params;");
							sb_js.append("$(\"#mydatagrid_").append(bo.getCode()).append("\").datagrid('reload');");
							sb_js.append("}");
							sb_js.append("}");

							// 添加默认清空搜索方法

							sb_js.append("function removeConditions_").append(bo.getCode()).append("(){");
							sb_js.append("if($.isFunction(window.myclear_").append(bo.getCode()).append("))").append("{myclear_").append(bo.getCode()).append("();}");
							sb_js.append("else{");
							for (QueryField qf : bo.getQueryFields()) {
								boolean flag = true;
								if (bo.getDepend() != null && qf.getCode().equalsIgnoreCase(bo.getDependParamK())) {
									flag = false;
								}
								if (flag && qf.getIsReadonly() == 0) {
									if (qf.getFieldTemplate() == null) {
										sb_js.append("$('#").append(qf.getCode().toUpperCase()).append("_").append(bo.getCode()).append("').val(\"\");");
									} else if (qf.getFieldTemplate().getType().name().equals("DATETIME") || qf.getFieldTemplate().getType().name().equals("DATE")) {
										sb_js.append("\t\t$('#").append(qf.getCode().toUpperCase()).append("').datebox('setValue','');\n");
									} else if (qf.getFieldTemplate().getType().name().equals("TIME")) {
										sb_js.append("\t\t$('#").append(qf.getCode().toUpperCase()).append("').timespinner('clear');\n");
									} else if (qf.getFieldTemplate().getType().name().equals("SELECT")) {
										sb_js.append("$('#").append(qf.getCode().toUpperCase()).append("_").append(bo.getCode()).append("').combotree('setValue','');");
									} else if (qf.getFieldTemplate().getType().name().equals("RADIO") || qf.getFieldTemplate().getType().name().equals("CHECKBOX")) {
										sb_js.append("$('#").append(qf.getCode().toUpperCase()).append("_").append(bo.getCode()).append("').combobox('setValue','');");
										sb_js.append("$('#").append(qf.getCode().toUpperCase()).append("_").append(bo.getCode()).append("').combobox('setText','');");
									}
								}
							}
							sb_js.append("query_").append(bo.getCode()).append("();");
							sb_js.append("}");
							sb_js.append("}");

						}
					}
					// 从表搜索结束
					// js部分结束

					// html部分开始

					// 主表
					sb_html.append("<form id=\"myform\" method=\"post\"");
					if (bizObject.isHasFileField()) {
						sb_html.append(" enctype=\"multipart/form-data\"");
					}
					sb_html.append(">\n");
					sb_html.append("\t<input type=\"hidden\" id=\"bizCode\" name=\"bizCode\" value=\"").append(bizObject.getCode()).append("\" />\n");
					for (BizField bf : bizObject.getBizFields()) {
						if (bf.getIsVisible() == 0 && bf.getIsFormField() == 1) {
							sb_html.append("\t<input type=\"hidden\" id=\"").append(bf.getCode().toUpperCase()).append("\" name=\"").append(bf.getCode().toUpperCase()).append("\" value=\"")
									.append(bf.getValue() == null ? "" : bf.getValue()).append("\" />\n");
						}
					}
					sb_html.append("\t<table width=\"100%\" border=\"0\">\n");
					int fieldsNumCurrentRow = 0;
					for (BizField bf : bizObject.getBizFields()) {

						// 便于jsp页面中取数据
						pageContext.setAttribute(bf.getCode().toUpperCase(), bf.getValue());

						if (bf.getIsVisible() == 1 && bf.getIsFormField() == 1) {
							fieldsNumCurrentRow += 1;
							boolean required = (bf.getIsPrimaryKey() == 1 || bf.getIsMandatory() == 1) ? true : false;
							boolean readonly = (bf.getCanUpdate() == 0 || bf.getIsReadonly() == 1) ? true : false;
							if (fieldsNumCurrentRow == 1)
								sb_html.append("\t\t<tr>\n");
							sb_html.append("\t\t\t<td  align=\"right\" width=\"").append(100 / bizObject.getMaxFieldsNumPerRow() * 0.25).append("%\" >\n\t\t\t\t").append(bf.getName())
									.append(required ? ":<font color=\"red\">*</font>\n\t\t\t</td>\n" : ":&nbsp;\n\t\t\t</td>\n");
							sb_html.append("\t\t\t<td width=\"")
									.append(100 / bizObject.getMaxFieldsNumPerRow() * 0.75)
									.append("%\" colspan=\"")
									.append(bf.getFieldTemplate() != null && (bf.getFieldTemplate().getType().equals("LONGTEXT") || bf.getFieldTemplate().getType().equals("RICHTEXT")) ? bizObject
											.getMaxFieldsNumPerRow() * 2 - 1 : 1).append("\">\n");

							if (bf.getFieldTemplate() == null && bf.getType().name().endsWith("CHAR")) {

								sb_html.append("\t\t\t\t<input type=\"text\" id=\"").append(bf.getCode().toUpperCase()).append("\" name=\"").append(bf.getCode().toUpperCase())
										.append("\" style=\"width: 150px;\" class=\"easyui-validatebox\" ").append(required ? "required=\"true\" " : " ").append(" value=\"")
										.append(bf.getValue() == null ? "" : bf.getValue()).append("\" ").append(bf.getValidType()).append(readonly ? " readonly=\"readonly\" />" : " />\n");
								sb_html.append("\t\t\t</td>\n");
							} else if (bf.getFieldTemplate() == null && (bf.getType().name().startsWith("INT") || bf.getType().name().equals("DECIMAL"))) {

								sb_html.append("\t\t\t\t<input type=\"text\" id=\"").append(bf.getCode().toUpperCase()).append("\" name=\"").append(bf.getCode().toUpperCase())
										.append("\" style=\"width: 150px;\" class=\"easyui-numberbox\" ").append(bf.getValidType()).append(required ? " required=\"true\" " : " ").append(" value=\"")
										.append(bf.getValue() == null ? "" : bf.getValue()).append("\" ").append(readonly ? " readonly=\"readonly\" " : " ")
										.append(bf.getMinValue() == null ? "" : "min=\"" + bf.getMinValue() + "\"").append(bf.getMaxValue() == null ? "" : "max=\"" + bf.getMaxValue() + "\"")
										.append(" title=\"").append(bf.getMinValue() == null ? "" : "最小值:" + bf.getMinValue()).append(bf.getMaxValue() == null ? "" : "最大值:" + bf.getMaxValue())
										.append("\" />\n");
								sb_html.append("\t\t\t</td>\n");
							} else if (bf.getFieldTemplate().getType().name().endsWith("TEXT")) {

								sb_html.append("\t\t\t\t<textarea style=\"width:100%;").append("\" id=\"").append(bf.getCode().toUpperCase()).append(" \" name=\"").append(bf.getCode().toUpperCase())
										.append("\"  class=\"easyui-validatebox\"").append(required ? " required=\"true\" " : " ").append(bf.getValidType())
										.append(readonly ? " readonly=\"readonly\" >" : " >").append(bf.getValue() == null ? "" : bf.getValue()).append("</textarea>\n");
								sb_html.append("\t\t\t</td>\n");
							} else if (bf.getFieldTemplate().getType().name().equals("DATETIME") || bf.getFieldTemplate().getType().name().equals("DATE")) {
								sb_html.append("\t\t\t\t<input type=\"text\" id=\"").append(bf.getCode().toUpperCase()).append("\" name=\"").append(bf.getCode().toUpperCase())
										.append("\" style=\"width: 150px;\" editable=\"false\" class=\"easyui-")
										.append(bf.getFieldTemplate().getType().name().equals("DATE") ? "datebox" : "datetimebox").append("\" ").append(bf.getValidType())
										.append(required ? " required=\"true\" " : " ").append(" value=\"").append(bf.getValue() == null ? "" : bf.getValue()).append("\" ")
										.append(readonly ? " disabled=\"true\" />" : " />\n");
								sb_html.append("\t\t\t\t<a href=\"javascript:void(0)\" class=\"easyui-linkbutton\" plain=\"true\" iconCls=\"icon-remove\" onclick=\"clearDatebox('")
										.append(bf.getCode().toUpperCase()).append("');\"").append(readonly ? "disabled" : "").append(">清除</a>\n");
								sb_html.append("\t\t\t</td>\n");
							} else if (bf.getFieldTemplate().getType().name().equals("TIME")) {
								sb_html.append("\t\t\t\t<input type=\"text\" id=\"").append(bf.getCode().toUpperCase()).append("\" name=\"").append(bf.getCode().toUpperCase())
										.append("\" style=\"width: 150px;\" editable=\"false\" class=\"easyui-timespinner\" showSeconds=\"true\" ").append(bf.getValidType())
										.append(required ? " required=\"true\" " : " ").append(" value=\"").append(bf.getValue() == null ? "" : bf.getValue()).append("\" ")
										.append(readonly ? " disabled=\"true\" />" : " />\n");
								sb_html.append("\t\t\t\t<a href=\"javascript:void(0)\" class=\"easyui-linkbutton\" plain=\"true\" iconCls=\"icon-remove\" onclick=\"clearTime('")
										.append(bf.getCode().toUpperCase()).append("');\"").append(readonly ? "disabled" : "").append(">清除</a>\n");
								sb_html.append("\t\t\t</td>\n");
							} else if (bf.getFieldTemplate().getType().name().equals("SELECT")) {
								sb_html.append("\t\t\t\t<input type=\"text\" id=\"").append(bf.getCode().toUpperCase()).append("\" name=\"").append(bf.getCode().toUpperCase())
										.append("\" style=\"width: 150px;\" editable=\"false\" class=\"easyui-combotree\" ")
										.append(" url=\"dragon/model/action/FieldTemplateHandler/loadData.ejw?bizCode=").append(bizObject.getCode()).append("&").append(queryString)
										.append("&bizfield").append("=").append(bf.getCode()).append("&root=").append(bf.getFieldTemplate().getDicRoot()).append("\" ")
										.append(bf.getFieldTemplate().getMultiple() == 1 ? " multiple=\"true\" " : "").append(bf.getValidType()).append(required ? " required=\"true\" " : " ")
										.append(" value=\"").append(bf.getValue() == null ? "" : bf.getValue()).append("\" ").append(readonly ? " disabled=\"true\" />" : " />\n");
								sb_html.append("\t\t\t\t<a href=\"javascript:void(0)\" class=\"easyui-linkbutton\" plain=\"true\" iconCls=\"icon-remove\" onclick=\"clearCombo('")
										.append(bf.getCode().toUpperCase()).append("');\"").append(readonly ? "disabled" : "").append(">清除</a>\n");
								sb_html.append("\t\t\t</td>\n");
							} else if (bf.getFieldTemplate().getType().name().equals("RADIO") || bf.getFieldTemplate().getType().name().equals("CHECKBOX")) {
								if (bf.getFieldTemplate().getProto() == 0) {
									sb_html.append("\t\t\t\t<input type=\"text\" id=\"").append(bf.getCode().toUpperCase()).append("\" name=\"").append(bf.getCode().toUpperCase())
											.append("\" style=\"width: 150px;\" editable=\"false\" class=\"easyui-combobox\" valueField=\"VALUE\" textField=\"TEXT\"  ")
											.append(" url=\"dragon/model/action/FieldTemplateHandler/loadData.ejw?bizCode=").append(bizObject.getCode()).append("&").append(queryString)
											.append("&bizfield").append("=").append(bf.getCode()).append("\" ").append(bf.getFieldTemplate().getMultiple() == 1 ? " multiple=\"true\" " : "")
											.append(bf.getValidType()).append(required ? " required=\"true\" " : " ").append(" value=\"").append(bf.getValue() == null ? "" : bf.getValue())
											.append("\" ").append(readonly ? " disabled=\"true\" />" : " />\n");
									sb_html.append("\t\t\t\t<a href=\"javascript:void(0)\" class=\"easyui-linkbutton\" plain=\"true\" iconCls=\"icon-remove\" onclick=\"clearCombo('")
											.append(bf.getCode().toUpperCase()).append("');\"").append(readonly ? "disabled" : "").append(">清除</a>\n");
									sb_html.append("\t\t\t</td>\n");
								} else {
									if (bf.getFieldTemplate().getType().name().equals("RADIO")) {
										if (bf.getFieldTemplate().getOptionsList() == null || bf.getFieldTemplate().getOptionsList().size() == 0) {
											for (Map<String, Object> map : FieldTemplateDao.getData(bizObject.getCode(), bf.getCode(), null, queryString.toString())) {
												sb_html.append("\t\t\t\t<input type='radio' id=\"").append(bf.getCode().toUpperCase()).append("\" name=\"").append(bf.getCode().toUpperCase())
														.append("\" value=\"").append(map.get("VALUE")).append("\" ")
														.append(map.get("VALUE").toString().trim().equals(bf.getValue() == null ? "" : bf.getValue().trim()) ? "checked" : "unchecked").append(" />")
														.append(map.get("TEXT")).append("\n");
											}
										} else {
											for (Map<String, Object> map : bf.getFieldTemplate().getOptionsList()) {
												sb_html.append("\t\t\t\t<input type='radio' id=\"").append(bf.getCode().toUpperCase()).append("\" name=\"").append(bf.getCode().toUpperCase())
														.append("\" value=\"").append(map.get("VALUE")).append("\" ")
														.append(map.get("VALUE").toString().trim().equals(bf.getValue() == null ? "" : bf.getValue().trim()) ? "checked" : "unchecked").append(" />")
														.append(map.get("TEXT")).append("\n");
											}
										}
									} else {
										if (bf.getFieldTemplate().getOptionsList() == null || bf.getFieldTemplate().getOptionsList().size() == 0) {
											for (Map<String, Object> map : FieldTemplateDao.getData(bizObject.getCode(), bf.getCode(), null, queryString.toString())) {
												sb_html.append("\t\t\t\t<input type='checkbox' id=\"").append(bf.getCode().toUpperCase()).append("\" name=\"").append(bf.getCode().toUpperCase())
														.append("\" value=\"").append(map.get("VALUE")).append("\" ").append(" />").append(map.get("TEXT")).append("\n");
											}
										} else {
											for (Map<String, Object> map : bf.getFieldTemplate().getOptionsList()) {
												sb_html.append("\t\t\t\t<input type='checkbox' id=\"").append(bf.getCode().toUpperCase()).append("\" name=\"").append(bf.getCode().toUpperCase())
														.append("\" value=\"").append(map.get("VALUE")).append("\" ").append(" />").append(map.get("TEXT")).append("\n");
											}
										}
										sb_html.append("\t\t\t\t<script>setValuesText('").append(bf.getCode().toUpperCase()).append("','").append(bf.getValue()).append("')</script>\n");
									}
									sb_html.append("\t\t\t</td>\n");
								}
							} else if (bf.getFieldTemplate().getType().name().equals("BDSELECTOR")) {
								sb_html.append("\t\t\t\t<input id='").append(bf.getCode().toUpperCase()).append("' name='").append(bf.getCode().toUpperCase()).append("' type='hidden' value='")
										.append(bf.getValue()).append("' />\n");
								sb_html.append("\t\t\t\t<input style=\"width: 150px;\" id=\"").append(bf.getCode().toUpperCase()).append("_Text\" name=\"").append(bf.getCode().toUpperCase())
										.append("_Text\" type='text' class='easyui-validatebox'  readonly=\"readonly\" ").append(bf.getValidType()).append(required ? " required=\"true\"" : "")
										.append(" value='").append(bf.getText()).append("' ").append(" />\n");
								sb_html.append("\t\t\t\t<a id=\"bdselector\" href=\"javascript:void(0);\" class=\"easyui-linkbutton\" plain=\"true\" iconCls=\"icon-add\" onclick=\"chooseBD('DefaultMod','");
								sb_html.append(bf.getCode().toUpperCase()).append("','").append(bf.getFieldTemplate().getCode()).append("','").append(bf.getFieldTemplate().getName()).append("',");
								sb_html.append(bf.getFieldTemplate().getWindowWidth()).append(",").append(bf.getFieldTemplate().getWindowHeight()).append(",")
										.append(bf.getFieldTemplate().getMaximizable()).append(",").append(bf.getFieldTemplate().getMaximize()).append(");\" >选择</a>\n");
								sb_html.append("\t\t\t\t<a href=\"javascript:void(0)\" class=\"easyui-linkbutton\" plain=\"true\" iconCls=\"icon-remove\" onclick=\"clearText('")
										.append(bf.getCode().toUpperCase()).append("');\"").append(readonly ? "disabled" : "").append(">清除</a>\n");
								sb_html.append("\t\t\t</td>\n");
							} else if (bf.getFieldTemplate().getType().name().equals("FILE")) {
								sb_html.append("<input type=\"hidden\" id=\"").append(bf.getCode().toUpperCase()).append("\" name=\"").append(bf.getCode().toUpperCase()).append("\" value=\"")
										.append(bf.getValue()).append("\"/>");
								sb_html.append("<input type=\"hidden\" id=\"").append(bf.getCode().toUpperCase()).append("_DELLIST\" name=\"").append(bf.getCode().toUpperCase())
										.append("_DELLIST\"/>");
								sb_html.append("<div id=\"").append(bf.getCode().toUpperCase()).append("_FILELIST\">");
								if (!StringUtils.isEmpty(bf.getValue())) {
									int index = 0;
									for (String s : bf.getValue().split(",")) {
										String[] fileinfo = s.split(":");
										String filestorename = fileinfo[0].substring(bizObject.getCode().toString().length() + 1, fileinfo[0].length());
										sb_html.append("<div id=\"")
												.append(bf.getCode().toUpperCase())
												.append("_OLDFILE_" + index + "\" filestorename=\"")
												.append(filestorename)
												.append("\"><a href=\"dragon/model/action/BizObjectHandler/getFile.ejw?path=" + s + "\" target=\"_blank\">" + fileinfo[1]
														+ "</a><a href=\"javascript:void(0)\" class=\"easyui-linkbutton\" plain=\"true\" iconCls=\"icon-cancel\" onclick=\"delFile('")
												.append(bf.getCode().toUpperCase()).append("_OLDFILE_" + index + "','" + filestorename + "');\">清除</a></div>");
										index += 1;
									}
								}
								sb_html.append("</div>");

								sb_html.append("<input id=\"").append(bf.getCode().toUpperCase()).append("_FILENUM\" type=\"hidden\" value=\"0\" />");
								sb_html.append("<input id=\"").append(bf.getCode().toUpperCase()).append("_FILENUM_0\" name=\"").append(bf.getCode().toUpperCase())
										.append("_FILENUM_0\" type=\"file\" style=\"display: none;\" onchange=\"setFilePath(this,'").append(bf.getCode().toUpperCase()).append("_FILENUM_0_PATH','")
										.append(bf.getFieldTemplate().getMultiple()).append("')\" accept=\"").append(bf.getFieldTemplate().getAcceptFileType()).append("\"/>");
								sb_html.append("<input id=\"").append(bf.getCode().toUpperCase()).append("_FILENUM_0_PATH\" type=\"text\" />");
								sb_html.append("<a href=\"javascript:void(0)\" class=\"easyui-linkbutton\" plain=\"true\" iconCls=\"ext-icon-upload\" onclick=\"upload('")
										.append(bf.getCode().toUpperCase()).append("_FILENUM_0');\">上传</a>");
								sb_html.append("<a href=\"javascript:void(0)\" class=\"easyui-linkbutton\" plain=\"true\" iconCls=\"icon-remove\" onclick=\"clearFilePath('")
										.append(bf.getCode().toUpperCase()).append("_FILENUM_0');\">清除</a>");
								if (bf.getFieldTemplate().getMultiple() == 1) {
									sb_html.append("<a href=\"javascript:void(0)\" class=\"easyui-linkbutton\" plain=\"true\" iconCls=\"ext-icon-file_add\" onclick=\"addUpload('")
											.append(bf.getCode().toUpperCase()).append("_FILENUM','").append(bf.getFieldTemplate().getAcceptFileType()).append("');\">增加</a>");
								}
							}
							if (fieldsNumCurrentRow == bf.getAdjacentFieldsNum()) {
								fieldsNumCurrentRow = 0;
								sb_html.append("\t\t</tr>\n");
							}
						}
					}
					sb_html.append("\t</table>\n");
					sb_html.append("</form>\n");
					sb_html.append("<table width=\"100%\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\" class=\"dialog_button_bar\">\n\t<tbody>\n\t\t<tr>\n\t\t\t<td>\n");
					sb_html.append("\t\t\t\t<div align=\"right\">\n");
					sb_html.append("\t\t\t\t\t<a href=\"javascript:void(0);\" class=\"easyui-linkbutton\" iconCls=\"icon-ok\" onclick=\"save();\">确定</a>\n");
					sb_html.append("\t\t\t\t\t<a href=\"javascript:void(0);\"  class=\"easyui-linkbutton\" iconCls=\"icon-cancel\" onclick=\"top.closeWindow('DefaultMod');\">关闭</a>\n");
					sb_html.append("\t\t\t\t</div>\n\t\t\t</td>\n\t\t</tr>\n\t</tbody>\n</table>\n");
					// 主表结束

					// 从表开始
					for (BizObject bo : bizObject.getDependby()) {
						String dependParamV = "";
						sb_html.append("<div style=\"margin-top: 10px;height: 400px;\"><div id=\"mydatagrid_").append(bo.getCode()).append("\" fit=\"true\"></div></div>");
						if (bo.getQueryFields() != null && !bo.getQueryFields().isEmpty()) {
							sb_html.append("<div id=\"datagridsearch_").append(bo.getCode()).append("\" class=\"datagridsearch\">");
							for (QueryField qf : bo.getQueryFields()) {
								boolean isDependParamK = false;
								if (bo.getDepend() != null && qf.getCode().equalsIgnoreCase(bo.getDependParamK())) {
									dependParamV = pageContext.getRequest().getParameter(bo.getDependParamV().toUpperCase());
									isDependParamK = true;
								}
								String paramValue = pageContext.getRequest().getParameter(qf.getCode().toUpperCase());
								boolean readonly = false;
								if (!StringUtils.isEmpty(paramValue)) {
									readonly = true;
								} else {
									paramValue = "";
								}

								sb_html.append("<p>");
								sb_html.append("<label>").append(qf.getName()).append(":</label>");
								if (qf.getFieldTemplate() == null) {
									sb_html.append("<input type=\"text\" id=\"").append(qf.getCode().toUpperCase()).append("\" style=\"width: 146px;\" class=\"easyui-validatebox\"")
											.append(readonly ? " readonly " : "").append(" value=\"").append(isDependParamK ? dependParamV : paramValue).append("\" />");
								} else if (qf.getFieldTemplate().getType().name().equals("DATETIME") || qf.getFieldTemplate().getType().name().equals("DATE")) {
									sb_html.append("<input type=\"text\" id=\"").append(qf.getCode().toUpperCase()).append("\" style=\"width: 150px;\" class=\"easyui-")
											.append(qf.getFieldTemplate().getType().name().equals("DATE") ? "datebox" : "datetimebox").append("\" readonly=\"readonly\"")
											.append(readonly ? " disabled " : "").append("  value=\"").append(isDependParamK ? dependParamV : paramValue).append("\" ")
											.append(isDependParamK ? " disabled " : "").append(" />");
								} else if (qf.getFieldTemplate().getType().name().equals("TIME")) {
									sb_html.append("<input type=\"text\" id=\"").append(qf.getCode().toUpperCase())
											.append("\" style=\"width: 150px;\" class=\"easyui-timespinner\" showSeconds=\"true\"  editable=\"true\"").append(readonly ? " disabled " : "")
											.append("  value=\"").append(isDependParamK ? dependParamV : paramValue).append("\" ").append(isDependParamK ? " disabled " : "").append(" />");
								} else if (qf.getFieldTemplate().getType().name().equals("SELECT")) {
									sb_html.append("<input type=\"text\" id=\"")
											.append(qf.getCode().toUpperCase())
											.append("\" style=\"width: 150px;\" class=\"easyui-combotree\"  url=\"dragon/model/action/FieldTemplateHandler/loadData.ejw?bizCode=" + bizObject.getCode()
													+ "&" + queryString + "&queryfield=" + qf.getCode().toUpperCase() + "&root=").append(qf.getFieldTemplate().getDicRoot()).append("\" ")
											.append(qf.getFieldTemplate().getMultiple() == 1 ? "multiple" : "").append(isDependParamK ? " disabled " : "").append(readonly ? " disabled " : "")
											.append("  value=\"").append(isDependParamK ? dependParamV : paramValue).append("\" />");
								} else if (qf.getFieldTemplate().getType().name().equals("RADIO") || qf.getFieldTemplate().getType().name().equals("CHECKBOX")) {
									sb_html.append("<input type=\"text\" id=\"")
											.append(qf.getCode().toUpperCase())
											.append("\" style=\"width: 150px;\" class=\"easyui-combobox\"  valueField=\"VALUE\" textField=\"TEXT\" url=\"dragon/model/action/FieldTemplateHandler/loadData.ejw?bizCode=")
											.append(bizObject.getCode()).append("&").append(queryString).append("&queryfield=").append(qf.getCode().toLowerCase()).append("\" ")
											.append(qf.getFieldTemplate().getMultiple() == 1 ? "multiple" : "").append(isDependParamK ? " disabled " : "").append(readonly ? " disabled " : "")
											.append("  value=\"").append(isDependParamK ? dependParamV : paramValue).append("\" />");
								}
								sb_html.append("</p>");
							}
							sb_html.append("<p>");
							sb_html.append("<a href=\"javascript:void(0);\" onclick=\"query_").append(bo.getCode())
									.append("();\" class=\"easyui-linkbutton\" plain=\"true\" iconCls=\"icon-search\">检索</a>");
							sb_html.append("<a href=\"javascript:void(0);\" class=\"easyui-linkbutton\" plain=\"true\" iconCls=\"icon-remove\" onclick=\"removeConditions_").append(bo.getCode())
									.append("();\">清空所有</a>");
							sb_html.append("</p>");
							sb_html.append("</div>");

						}
					}
					// 从表结束
					js = sb_js.toString();
					html = sb_html.toString();
				}

			} else {
				js = "$(function(){top.showMsg(\"\", \"未发现数据模型：！\", false);});";
				html = "<font color=\"red\">未发现模型：</font>";
			}

			pageContext.setAttribute("js", js);
			pageContext.setAttribute("html", html);
		} catch (Exception e) {
			throw new JspException(e);
		}

		return EVAL_BODY_INCLUDE;
	}

	public String getJs() {
		return js;
	}

	public void setJs(String js) {
		this.js = js;
	}

	public String getHtml() {
		return html;
	}

	public void setHtml(String html) {
		this.html = html;
	}

}
